package com.prince.web.config;

import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.util.DruidPasswordCallback;

/**
 * Created by Administrator on 2017/9/29.
 */
public class DBPasswordCallback extends DruidPasswordCallback {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String PUBLIC_KEY_STRING = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8p7x51DTthi6aqFaMVdNJY4QfsmI0SfFiopmd" + 
    		"QBcOTV61RFa++HBffbr15fwjC8nd1ouYLyd14GVcEwwgmE4yIMO4eWhBho3AIc2fwoZILm5U4EoJ" + 
    		"6N2RZjrVAYXpl6sew6alzGvOqrn70jN1D3XYhadKeMq0FUs2J2DnPV/wvwIDAQAB";

    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        String pwd = properties.getProperty("password");
        if (StringUtils.isNoneBlank(pwd)) {
            //TODO
            String password = "";
          
            try {
                password = ConfigTools.decrypt(PUBLIC_KEY_STRING, pwd);
//                System.err.println("-------------------------------");
//                System.err.println(password);
                setPassword(password.toCharArray());
            } catch (Exception e) {
                setPassword(password.toCharArray());
                e.printStackTrace();
            }
        }
    }
    
}
